
"use strict"
;(function($, window, document, undefined) {
	$.extend({
		//初始化界面dom
		initPage:function(){
			//获取周节次
			$.getNodes();
			//获取课程表数据
			$.getTimeTable();
		},
		//获取周节次
		getNodes:function(){
			$(".teacherName").text(localStorage.getItem("teacherName")+"的课程表");
			fnAjax.method_4(
				url_join("schedule-v1/session"),
				{},
				"post",
				function(data){
					console.log(data);
					console.log($("table .week").length);
					var len_tds = $("table .week").length;
					var tds = "";
					for(var i=0;i<len_tds;i++){
						tds += '<td class="classGroup_classroom"></td>';
					}
					var trs = "";
					for(var i=0;i<data.data;i++){
						trs += '<tr class="text-c"><td class="node">第'+ (i+1) +'节</td>'+ tds +'</tr>';
					}
					$("table tbody").html(trs);
					//渲染表格单元，添加星期和节次属性，
					$("tr .classGroup_classroom").each(function(i){
						var index = $(this).index();
						var nDataWeek = $("thead th").eq(index).attr("data-week");
						$(this).attr({
							"data-week":nDataWeek,
							"data-node":$(this).parent("tr").index()+1
						});
						
					});
					
				}
			);
		},
		//获取课程表数据
		getTimeTable:function(){
			fnAjax.method_4(
				url_join("attendance/schedule"),
				{staff_id:localStorage.getItem("nId")},
				"post",
				function(data){
					console.log(data);
					$.each(data.data.schedule, function(i,v) {
						$(".classGroup_classroom").each(function(k){
							if($(this).attr("data-week") == v.day && $(this).attr("data-node") == v.class_hour){
								var sHtml = '<span class="label label-primary mg-5">'+ v.class_group +'</span>'+
											'<span class="label label-success mg-5">'+ v.room +'教室</span>';
							
								$(this).html(sHtml);
							}
						});
					});
				}
			);
		},
		
	});
})(jQuery, window, document);